package com.chia.multienty.core.domain.enums;

import com.chia.multienty.core.domain.vo.LabelValuePair;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum LabelType {
    PRODUCT(1, "商品"),
    PRODUCT_CASE(2, "案例"),
    ;
    @JsonValue
    private Integer value;
    private String describe;

    public static List<LabelValuePair> getList() {
        return Arrays.stream(values())
                .map(m -> new LabelValuePair(m.describe, m.value, false))
                .collect(Collectors.toList());
    }

    @JsonCreator
    public static LabelType valueOf(Integer value) {
        if(value == null) {
            return null;
        }
        for (LabelType type : LabelType.values()) {
            if (value.equals(type.getValue())) {
                return type;
            }
        }
        return null;
    }
}

